import TableLyout from '@/components/commonPublic/tableLyout.vue'
import publicForm from "@/components/materialDataManage/fromCom.vue"; //弹框form
import lineEcharts from "@/components/machineNetworkManage/analysisDataManage/cementQuality/lineEcharts.vue"; //折线图
import messageBox from "@/components/public/messageBox"; //主页面分页
import actions from "@/actions";


import formJs from "./regexDetail.js"; //新增弹框配置
import {
    getTestMortarTrendsList, //列表页接口
    getBaseDataitemDetailByItemCode, //字典
    getUserCompanyTreeList, //树状图
} from "@/api/request.js";


export default {
    name: "rebarQuality",
    data() {
        return {
            name: "rebarQuality",
            searchObj: formJs.searchObj, //搜索条件
            loading: false,
            btnObj: [], //按钮
            tableData: {},//全部数据
            userNature: null, //用户Nature
            showMsgBox: false,
            msgTip: "请先选中数据行！",
            msgType: 1,
            projectsObj: [], //项目名
            tendersObj: [],
            falgId: null,
            
            
            // 图表
            groupNmu: 0,
            getList: {
                MachineId: "",
                fCementtype: "",
                fCloseoperation: "",
                keyWord: "",
                modelType: "0",
                page: 1,
                pageSize: 15,
                upNum: "",//波动上限
                downNum: "",//波动下限
                taskNumber: "",//区段
                keyType: "", //上方查询条件材料种类
                fBrand: "",//牌号
                fprojectid: "",
                fCompanyid: "", //左侧选中组织机构id
                fAge: "",//上方查询条件龄期
                fStrength: "", //上方查询条件强度等级
                userId: "", //查询待办或已办时传 列表页查询不传
                startDates: "", //进场开始时间
                endDates: "", //进场结束时间
                timeDates: [],
            },
            // 折线图
            lineChartData: null,//折线图数据
            echartsTitle: "",//折线图标题
            xName: "时间",//X轴名称
            yName: "(MPa)",//Y轴名称
            // 折线图
            // 图表

           

        };
    },
    components: {
        TableLyout,
        publicForm,
        messageBox,
        lineEcharts,
    },
    mounted() {
        actions.onGlobalStateChange((state, prev) => {
            this.userInfo = prev.currentUser
        }, true);

        this.getList = {
            fprojectid: "",
            MachineId: "",
            fCementtype: "",
            fCloseoperation: "",
            keyWord: "",
            modelType: "0",
            page: 1,
            pageSize: 15,
            upNum: "",//波动上限
            downNum: "",//波动下限
            taskNumber: "",//区段
            keyType: "", //上方查询条件材料种类
            fBrand: "",//牌号

            fCompanyid: "", //左侧选中组织机构id
            fAge: "",//上方查询条件龄期
            fStrength: "", //上方查询条件强度等级
            userId: this.userInfo.userId, //查询待办或已办时传 列表页查询不传
            startDates: "", //进场开始时间
            endDates: "", //进场结束时间
            timeDates: [],
        };
        this.getStrengthgrade("StrengthGrade3");//强度
        this.getSpecimenage("SpecimenAge3");//龄期
    },
    methods: {
        getBtnName(name, status) {
            console.log(name, status);
        },
        confirmMsg() {
            this.showMsgBox = false;
        },
        reset(e) {
            this.getList = this.$options.data.call(this).getList
            this.getList.fprojectid = e
        },
        // 选择项目名称
        selectCompany(e) {
            this.companyName = e.F_ProjectName;
            this.getList.fDepartmentid = e.F_ProjectId;
            this.projectName = "";
            this.getList.fCompanyid = "";


            this.yj_searchForm(this.getList);
        },
        // 选择施工单位
        selectProject(e) {

            this.projectName = e.F_CompanyName;
            this.getList.fCompanyid = e.F_CompanyId;
            // this.yj_searchForm(this.getList);
        },
        async getTender(e) {
            await this.$http(
                " http://172.18.5.31:8300/IOTManagement/Base/Company/getGXJLBaseCompanyList.do?projectId=" +
                e, {
                    headers: {
                        "Content-Type": "application/json",
                        Authorization: localStorage.getItem("access_token"),
                    },
                }
            ).then((res) => {
                if (res.status == 200) {
                    var data = res.data.data.GXCompanyList;
                    this.tendersObj = [];
                    if (data.length == 0) {
                        this.$message.warning({
                            content: "有其他人员登录此账号！",
                            duration: 1000,
                        });
                        setTimeout(() => {
                            window.location.href = "http://172.18.5.201:1080/login";
                        }, 1200);
                    } else   if (data.length == 1) {
                        data.map((item) => {
                            this.tendersObj.push({
                                fItemName: item.sectionName,
                                fItemValue: item.sectionId,
                            });
                        });
                        this.getList.fCompanyid = data[0].sectionId;
                    } else {
                        this.tendersObj = [{
                            fItemName: "所有标段",
                            fItemValue: "",
                        }, ];
                        data.map((item) => {
                            this.tendersObj.push({
                                fItemName: item.sectionName,
                                fItemValue: item.sectionId,
                            });
                        });
                    }
                }
            });
        },
        selectTender(e) {
            this.getList.stationId = "";
            this.getList.machineId = "";
            this.bhzDataList = [];
            this.bhjDataList = [];
           
        },
        // 获取列表数据
        yj_searchForm(data) {
            this.groupNmu = 0
            var BrandText = "";
            if (data.fStrength == "强度等级") {
                data.fStrength = "";
                BrandText = "强度等级";
            } else {
                BrandText = data.fBrand;
            }
            if (data.fAge == "龄期(天)") {
                data.fAge = "";
            }
            this.echartsTitle = data.startDates + "至" + data.endDates + "【" + BrandText + "】砂浆质量波动图(抗压)";
            window.sessionStorage.setItem(
                "GxEmbedded-machineNetworkManage_getList",
                JSON.stringify(data)
            );
            var id;
            if (data.fCompanyid != "") {
                id = data.fCompanyid;
            } else {
                id = data.fprojectid;
            }
            var obj = {
                fCompanyid: id, // 左侧选中组织机构id
                fAge: data.fAge, //上方查询条件龄期
                fStrength: data.fStrength, //上方查询条件强度等级
                userId: this.userInfo.id, //用户id
                startDates: data.startDates, //开始时间
                endDates: data.endDates, //结束时间
            }
            this.loading = true;
            getTestMortarTrendsList(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        var that = this;

                        that.loading = false;
                        that.tableData = res.data;
                        // 折线区域数据
                        that.lineChartData = {
                            xitems: [], //试验日期  X
                            yitems: [],//最大力强度  Y
                            fSamplenostr: [],//试件编号
                            fProjectlocation: [],//工程部位
                        }
                        if (res.data.listky.length != 0) {
                            that.groupNmu = res.data.listky.length;
                            res.data.listky.map(item => {
                                that.lineChartData.xitems.push(item.fTestdates);
                                that.lineChartData.yitems.push(item.fStrengthmeasurement);
                                that.lineChartData.fSamplenostr.push(item.fSamplenostr);
                                that.lineChartData.fProjectlocation.push(item.fProjectlocation);

                            })
                        }
                        // 折线区域数据

                    } else {
                        this.$message.error({
                            content:"列表数据获取失败"+res.msg,
                            duration: 1000
                        });
                        this.loading = false;
                    }
                })
                .catch((error) => {
                    console.log("列表数据 接口出错", error.msg);
                    this.loading = false;
                });
        },

        selectTime(e) {
            if (e[0] != "" && e[1] != "") {
                this.getList.startDates = e[0]; // 开始时间
                this.getList.endDates = e[1]; // 截至时间
            } else {
                this.getList.startDates = ""; // 开始时间
                this.getList.endDates = ""; // 截至时间
            }
            this.getList.timeDates = [e[0], e[1]]
            this.yj_searchForm(this.getList);

        },

        getDate() {
           
            if (JSON.parse(sessionStorage.getItem("GxEmbedded-machineNetworkManage_getList"))) {
                var getList = JSON.parse(sessionStorage.getItem("GxEmbedded-machineNetworkManage_getList"));
                // var id;
                // if (getList.fCompanyid != "") {
                //     id = getList.fCompanyid;
                // } else {
                //     id = getList.fprojectid;
                // }
                this.getList.startDates = getList.startDates; // 开始时间
                this.getList.endDates = getList.endDates;  // 截至时间
                this.getList.timeDates = getList.timeDates;
            } else {
                this.getList.startDates = this.common.getDay(-90); // 开始时间
                this.getList.endDates = this.common.getDay(0); // 截至时间
                this.getList.timeDates = [this.getList.startDates, this.getList.endDates];
            }
        },

        // 字典项
        // 强度等级
        getStrengthgrade(data) {
            getBaseDataitemDetailByItemCode({ fItemcode: data })
                .then((res) => {
                    if (res.errcode == 0) {
                        this.searchObj[3].options = [
                            {
                                value: "强度等级",
                                label: "强度等级"
                            }
                        ];
                        res.data.baseDataitemdetailList.map((item) => {
                            this.searchObj[3].options.push({
                                value: item.fItemname,
                                label: item.fItemvalue,
                            });
                        });
                        this.getList.fStrength = this.searchObj[3].options[0].label;
                        this.getDate();

                    } else {
                        this.$message.error({
                            content:"强度等级"+res.msg,
                            duration: 1000
                        });
                    }
                })
                .catch(() => {
                    console.log("字典--强度等级接口报错");
                });
        },
        //试件龄期
        getSpecimenage(data) {
            getBaseDataitemDetailByItemCode({ fItemcode: data })
                .then((res) => {
                    if (res.errcode == 0) {
                        this.searchObj[4].options = [{
                            value: "龄期(天)",
                            label: "龄期(天)"
                        }];
                        res.data.baseDataitemdetailList.map((item) => {
                            this.searchObj[4].options.push({
                                value: item.fItemname,
                                label: item.fItemvalue,
                            });
                        });
                        this.getList.fAge = this.searchObj[4].options[0].label;

                    } else {
                        this.$message.error({
                            content:"试件龄期"+res.msg,
                            duration: 1000
                        });
                    }
                })
                .catch(() => {
                    console.log("字典--试件龄期接口报错");
                });
        },
        // 字典项
    },
};